<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important
}

.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}
</style>
</head>
<body class="no-skin">
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.xmiles.cn/commentloading.gif" class="load_img"
		style="display: none" />
	<div class="page-content">
		<div class="page-header"
			style="margin-bottom: 0px; padding-bottom: 10px;"></div>

		<form id="queryForm" method="post" enctype="multipart/form-data">
			<input type="hidden" id = "operator" name="operator" value="<%=((UserVO) session.getAttribute(WebConstants.SESSION_ATTRIBUTE_USER)).getUsername() %>"/>
			<input type="hidden" id = "isFileUp" name="isFileUp" value="${paramsMap.flag }"/>
			<div class="page-content-area">
				<div class="row">
					<div class="col-sm-12">
						<div class="widget-box"
							style="border: 0px solid #ccc; border-top: none; border-bottom: none;">
							
							<div class="widget-header widget-header-blue widget-header-flat">
								<h4 class="widget-title">选择条件进行查询</h4>

								<div class="widget-toolbar">
									<a href="#" data-action="collapse"> <i
										class="ace-icon fa fa-chevron-up"></i>
									</a>
								</div>
							</div>

							<div class=" widget-body">
								<!-- <div class="widget-main" style="padding:12px;border:0px solid #ccc; border-top:none;border-bottom:none;"> -->
								<div class="widget-main">
									<%-- <div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3"
										style="text-align: left">
										<span id="upload"> <input id="uploadfile_wx"
											name="upload" type="file" size="1" style="display: none" />
											<input id="uploadbtn_wx" type='button' class='btn'
											value='导入基础数据' />
										</span>
									</div> --%>
			
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"  style="text-align:right">手机号</label>
										<div class="col-sm-8">
											<input type="text" name="cPhone" style="width:100%;text-align:left;">
										</div>
									</div>
															
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right">申请时间:</label>
										<div class="col-sm-8">
											<div class="input-daterange input-group">
												<input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" name="startTime" id="startTime">
												<span class="input-group-addon" style="width: 6px"> <i
													class="fa fa-exchange"></i>
												</span> <input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" name="endTime" id="endTime">
											</div>
										</div>
									</div>

									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right">放贷时间:</label>
										<div class="col-sm-8">
											<div class="input-daterange input-group">
												<input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" name="handleStartTime"
													id="handleStartTime"> <span
													class="input-group-addon" style="width: 6px"> <i
													class="fa fa-exchange"></i>
												</span> <input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" name="handleEndTime"
													id="handleEndTime">
											</div>
										</div>
									</div>
									
							 		<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-6 control-label"
											style="text-align: right">产品: </label>
										<div class="col-sm-6">
											<s:select name="product_id"
												list="%{productList}" 
												listKey="prd_id"
												listValue="prd_name" headerKey="" headerValue="--请选择--"
												cssClass="form-control"></s:select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-6 control-label"
											style="text-align: right">平台: </label>
										<div class="col-sm-6">
											<select name="platform">
												<option value="">请选择</option>
												<option value="0">通用</option>
												<option value="1">android</option>
												<option value="2">ios</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-6 control-label"
											style="text-align: right">渠道: </label>
										<div class="col-sm-6">
											<s:select name="channel"
												list="%{channelList}" listKey="channel_code"
												listValue="channel_name" headerKey="" headerValue="--请选择--"
												cssClass="form-control"></s:select>
										</div>
									</div>
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-6 control-label"
											style="text-align: right">合作方: </label>
										<div class="col-sm-6">
											<s:select name="partnerId"
												list="%{partnerList}" listKey="id"
												listValue="name" headerKey="" headerValue="--请选择--"
												cssClass="form-control"></s:select>
										</div>
									</div>
								</div>
								<!-- /.widget-main -->
							</div>
							<!-- /.widget-body -->
						</div>
						<!-- /.widget-box -->
					</div>
					<!-- /.col-sm-12 -->
					<div class="col-md-12 center">
						<div class="clearfix form-actions">
						
							<button class="btn btn-purple  no-border" type="button"
								name="btn-query" onclick="query_any(2)" id="btn-query">
								<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
								查询
							</button>
							&nbsp;&nbsp;&nbsp;
							<span id="upload"> 
								<input id="uploadfile_wx"name="upload" type="file" size="1" style="display: none" />
								<input id="uploadbtn_wx" type='button' class='btn' value='导入基础数据' />
							</span>
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey  no-border" type="button"
								name="handlerecord" id="handlerecord">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
								确认录入所选项
							</button>
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey  no-border" type="button"
								name="cleanFileBuf" id="cleanFileBuf">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
								清除文件缓存
							</button>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<table id="jquery-table"
							class="table table-striped table-bordered table-hover">
						</table>
					</div>
					<!-- /.col -->
				</div>
				<!-- /.row -->

			</div>
			<!-- /.page-content-area -->
		</form>
	</div>
	<!-- /.page-content -->

	<%@ include file="/common/common-js.jsp"%>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script type="text/javascript"
		src="${ctx}/ace/js/jquery.dataTables.min.js"></script>
	<!-- inline scripts related to this page -->
	<script type="text/javascript">
	
	
		jQuery(function($) {
			if ("" != "${paramsMap.message}") {
				message = "${paramsMap.message}";
				alert(message);
			}
		});

		$('#uploadbtn_wx').click(function() {
			$('#uploadfile_wx').trigger('click');
		});

		$('#uploadfile_wx').change(function() {
			var filename = $("#uploadfile_wx").val();
			var extStart = filename.lastIndexOf(".");
			var ext = filename.substring(extStart+1, filename.length).toUpperCase();
			
			if ("XLSX" != ext && "XLS" != ext) {
				alert("文件格式错误,请导入excel文件");
				return;
			}
			var file = this.files[0];
			var r = new FileReader();
			r.readAsDataURL(file);
			$(r).load(function() {
				var $form = document.forms["queryForm"];
				$form.action = ctx + "/loanInput/uploadrepeatfinance.action";
				$form.submit();
			});

		});

		
		$(document).ready(function() {
			
			query_any();
		});
		
		$('#handlerecord').click(function() {

			
			var isFileUp = $("#isFileUp").val();
			if(isFileUp == 0){
				alert("请上传文件");
				return;
			}

			if (window.confirm('确认导入数据')) {
				
				
				var ids = new Array();
				var i = 0;
				$(":checkbox").each(function(){
					if($(this).is(':checked')){
						var id = $(this).val();
						ids.push(id);
					}
				});
				
				
				if(ids==""){
					alert("无勾选数据");
					return;
				}
				var operator = $("#operator").val();
				
				var data = $('#queryForm').serializeObject();
				$.ajax({
					"type" : "POST",
					"data" : {"operator":operator,"ids[]":ids},
					"dataType" : 'json',
					//"url" : ctx + '/loanInput/handleRepeatRecord.action?ids='+ids,
					"url" : ctx + '/loanInput/handleRepeatRecord.action',		
					"timeout" : 300000,
					"success" : function(data) {
						if (data.status == 1) {
							$("#isFileUp").val(0);
							alert("录入数据库成功");
							query_any();
						} else {
							alert(data.message);
						}
					},
					"error" : function() {
						alert("处理失败");
					}
				});
			}
		});

		
		$('#cleanFileBuf').click(function() {
			
			var data = $('#queryForm').serializeObject();
			$.ajax({
				"type" : "POST",
				"dataType" : 'json',
				"url" : ctx + '/loanInput/cleanFileBuf.action',
				"timeout" : 300000,
				"success" : function(data) {
					if (data.status == 1) {
						alert("删除文件缓存成功");
						query_any();
					} else {
						alert("无文件缓存");
						query_any();
					}
				},
				"error" : function() {
					alert("处理失败");
				}
			});
			
			
		});

		var souceList = null;
		//【查询】按钮Click事件
		function query_any(flag) {
			
			$(".load_bg").removeAttr("style");
			$(".load_img").removeAttr("style");
			if (jqTable != null) {
				jqTable.fnDraw();
				var isFileUp = $("#isFileUp").val();
				if(isFileUp == 0){
					
					//$("#cbox").hide();
				}
				if(isFileUp == 1){
					
					//$("#cbox").show();
				}
			} else {
				loaddata(flag);
			}
		}
		var jqTable = null;
		var loaddata = function(flag) {
			jQuery(function($) {
				
				var reqUrl;
			
				if(flag == 1){
					reqUrl = "/loanInput/getTempList.action";
				}else{
					reqUrl = "/loanInput/getDataList.action";
				}
				
				jqTable = $('#jquery-table')
						.dataTable(
								{
									//数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
									"columnDefs" : [
											{
												"title" : '<input type="checkbox" id="checkAll"/>',	
												"name" : "position",
												"data" : "position",
												"targets" : [ 0 ],
												"bSortable" : false,
												"render" : function(value, type, row) { // 返回自定义内容
													return " <input type='checkbox' id='cbox' name='PK' value='"+value+"'/> ";
												}
											},
											{
												"title" : '所属产品',
												"targets" : [ 1 ],
												"name" : "prdName",
												"data" : "prdName", //JSON返回属性
												"bSortable" : false,
											},
											{
												"title" : '所属渠道',
												"targets" : [ 2 ],
												"name" : "channelName",
												"data" : "channelName", //JSON返回属性
												"bSortable" : false,
											},
											{
												"title" : '合作方ID',
												"targets" : [ 3 ],
												"name" : "partnerId",
												"data" : "partnerId", //JSON返回属性
												"bSortable" : false,
											},
											{
												"title" : "合作方名",
												"name" : "partnerName",
												"data" : "partnerName",
												"targets" : [ 4 ],
												"bSortable" : false,
											},
											{
												"title" : "客户手机号",
												"name" : "mobnum",
												"data" : "mobnum",
												"targets" : [ 5 ],
												"bSortable" : false,
											},
											{
												"title" : "平台",
												"name" : "platformName",
												"data" : "platformName",
												"targets" : [ 6 ],
												"bSortable" : false,
											},
											{
												"title" : "提交申请时间",
												"name" : "applyTime",
												"data" : "applyTime",
												"targets" : [ 7 ],
												"bSortable" : false,
											},
											{
												"title" : "放贷时间",
												"name" : "loanTime",
												"data" : "loanTime",
												"targets" : [ 8 ],
												"bSortable" : false,
											},
											{
												"title" : "放贷金额",
												"name" : "loanMoney",
												"data" : "loanMoney",
												"targets" : [ 9 ],
												"bSortable" : false,
											},
											{
												"title" : "结算金额",
												"name" : "settlementMoney",
												"data" : "settlementMoney",
												"targets" : [ 10 ],
												"bSortable" : false,
											},
											{
												"title" : "创建时间",
												"name" : "ctime",
												"data" : "ctime",
												"targets" : [ 11 ],
												"bSortable" : false,
											},
											{
												"title" : "操作人",
												"name" : "operator",
												"data" : "operator",
												"targets" : [ 12 ],
												"bSortable" : false
											},
											{
												"title" : "确认时间",
												"name" : "confirmTime",
												"data" : "confirmTime",
												"targets" : [ 13 ],
												"bSortable" : false,
											},
											{
												"title" : "序号",
												"name" : "position",
												"data" : "position",
												"targets" : [ 14 ],
												"bSortable" : false,
											},
											 ],
									"sAjaxSource" : ctx + reqUrl,
									"fnServerData" : function(sSource, aoData,
											fnCallback) {//从服务器请求数据
										var data = $('#queryForm')
												.serializeObject();
										data.aoData = JSON.stringify(aoData);
										$.ajax({
											"dataType" : 'json',
											"type" : "POST",
											"url" : sSource,
											"data" : data,
											
											"success" : function(resp) {
												
												$(".load_bg").attr("style",
														"display:none");
												$(".load_img").attr("style",
														"display:none");
												$("#hidden_pass").attr("style",
														"display:block");
												$('#jquery-table').removeClass(
														"dataTable"); 
												fnCallback(resp);
												initListPage(); 
											},
											"error" : function(XMLHttpRequest,
													textStatus, errorThrown) {
												$(".load_bg").attr("style",
														"display:none");
												$(".load_img").attr("style",
														"display:none");
												alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效

											}
										});
									},
									"fnRowCallback" : function(nRow, aData,
											iDisplayIndex, iDisplayIndexFull) {
			

										$(nRow)
												.on(
														'click',
														'td .infoID',
														function(index) {
															var id = $(this)
																	.val();
															var url = "/loanInput/editCps.action?id="
																	+ id;
															url = encodeURI(url);
															openDialogWithRand(
																	url,
																	1400,
																	1000,
																	"",
																	function(
																			data) {
																	});
														});

									},
									"bDestroy" : true,
									"bScrollInfinite" : true,
									"sScrollXInner" : "100%",
									"sScrollY" : "100%",//如果不设置，IE会有问题
									"aaSorting" : [ [ 1, "desc" ] ]
								//初始化加载，默认按第几列排序、排序方式（列从0开始计算）
								});
			});
			var isFileUp = $("#isFileUp").val();
			if(isFileUp == 0){
				
				//$("#cbox").hide();
			}
			if(isFileUp == 1){
				
				//$("#cbox").show();
			}
		}
		
		//全选Checkbox事件
		$(document).on('click', '#checkAll' , function(){
			var that = this;
			$("input[name='PK']").each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
		});
		
		
		//时间控件
		jQuery(function($) {
			$(".date-picker").datepicker({
				autoclose : true
			}).next().on(ace.click_event, function() {
				$(this).prev().focus();
			});
			$("#campaign_id").combobox();
		});

		function opdanger(id) {
			var status = window.confirm("确认置为处理失败");
			$.ajax({
				"type" : "POST",
				"dataType" : 'json',
				"url" : ctx + '/loanInput/handlefail.action?id=' + id,
				"timeout" : 300000,
				"success" : function(data) {
					if (data.status == 1) {
						query_any();
					} else {
						alert(data.message);
					}
				},
				"error" : function() {
					alert("处理失败");
				}
			});
		}

		function editCPS(id) {
			openDialogWithRand("/loanInput/getBase.action?id=" + id, 1400, 1000,
					"cps编辑", function(data) {
						query_any();
						if (data == 'success') {
						}
					});
		}
	</script>

</body>
</html>